package com.cskaoyan.controller;

import com.cskaoyan.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

/**
 * @author stone
 * @date 2022/03/23 12:02
 */
@Controller
public class AccountController {

    @Autowired
    AccountService accountService;

    @RequestMapping("api/transfer")
    @ResponseBody
    public String transfer(HttpServletRequest request) throws SQLException {
        //使用请求：localhost:端口号/api/transfer?fromId=1&destId=2&money=100
        // 这个是通过request获得参数，大家把参数转换为你需要的格式，然后完成转账业务
        //整合前面的代码^_^
        String fromId = request.getParameter("fromId");
        String destId = request.getParameter("destId");
        String money = request.getParameter("money");

        int fromid = Integer.parseInt(fromId);
        int destid = Integer.parseInt(destId);
        double moneyd = Double.parseDouble(money);

        accountService.transfer(fromid,destid,moneyd);

        return "transfer success";
    }
}
